package cn.edu.sjtu.se.dslab.component.design;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * 
 * @author longshaohang
 * 
 */

@Entity
@Table(name = "design_pattern_property")
public class DesignPatternProperty implements Serializable {

	private static final long serialVersionUID = -1211996715887972062L;

	private long id;
	private String name;
	private Date createTime;
	private String description;
	private DesignPattern designPattern;

	/*
	 * getter and setter
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Column(nullable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false, insertable = true, updatable = false, name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}


	@Column(nullable=false)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@ManyToOne(cascade = { CascadeType.ALL })
	@JoinColumn(name = "design_pattern_id", nullable = false)
	public DesignPattern getDesignPattern() {
		return designPattern;
	}

	public void setDesignPattern(DesignPattern designPattern) {
		this.designPattern = designPattern;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		DesignPatternProperty other = (DesignPatternProperty) obj;
		if (id != other.id)
			return false;
		return true;
	}

}
